import axios from "axios";
import { resginInterceptors } from './interceptors'

const service = axios.create({
    timeout: 10000
})
resginInterceptors(service)

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const httpService = (method: string, url: string, data?: any) => {
    const httpOption = {
        method: method,
        url
    }
    if (data) {
        if (method === 'GET') {
            Object.assign(httpOption, {
                params: data
            })
        } else {
            Object.assign(httpOption, {
                data: data
            })
        }
    }
    return new Promise((resolve, reject) => {
        service(httpOption as any).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}


export default httpService